#!/usr/bin/python3
# -*- encoding: utf-8 -*-

import pymysql
import time
import datetime
import uuid
import os
import xlrd

os.chdir(os.path.abspath(os.path.dirname(__file__)))

file_name = '人员信息导出.xls'

# 打开文件
wb = xlrd.open_workbook(file_name)
sh = wb.sheet_by_index(0)

dataInfo = ""
for rowNum in range(sh.nrows):
    rowVale = sh.row_values(rowNum)
    if str(rowVale[4]).split('.')[0] == '1':
        dataInfo += "update V_TBL_FUNC_EMPLOYEE set GENDER = '{}' where name = '{}' ;\n".format(
            'M', rowVale[3])
        # print("update V_TBL_FUNC_EMPLOYEE set GENDER = '{}' where name = '{}'".
        #       format('M', rowVale[3]))
    else:
        dataInfo += "update V_TBL_FUNC_EMPLOYEE set GENDER = '{}' where name = '{}' ;\n".format(
            'F', rowVale[3])
        # print("update V_TBL_FUNC_EMPLOYEE set GENDER = '{}' where name = '{}'".
        #       format('F', rowVale[3]))

# 1、打开txt文件     w:覆盖以前的内容；a:在最后追加
file_handle = open('data.txt', mode='w')
# 2、向文件写入数据
file_handle.write(dataInfo + ' \n')
# 3、关闭文件
file_handle.close()

# print(sh.row_values(1)[4])

# print(sh.nrows[0])

# cus_codeList = [
#     str(sh.cell(i, 1).value).split('.')[0] for i in range(1, sh.nrows)
# ]

# titles = []
# for rowNum in range(sh.nrows):
#     rowVale = sh.row_values(rowNum)

# if rowNum == 0:
#     titles = rowVale
# else:
#     data = rowVale
#     # print(data)
#     result = {}
#     # print(titles)
#     for j in range(len(titles)):
#         result[titles[j]] = data[j]

#     print(result['性别'])
